import { Button } from "antd";
import React from "react";
import { connect } from "./../../source/react-redux/index";
import actions from "./../../store/actions/index.js";
class Name extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }
  changeAge = () => {
    let { setActionsAge } = this.props;
    setActionsAge();
  };
  add = () => {
    let { setNumber } = this.props;
    setNumber();
  };
  render() {
    const { name, number } = this.props;
    return (
      <div>
        姓名：<span>{name}</span>
        <span style={{ marginLeft: "20px" }}>数字：{number}</span>
        <Button onClick={this.changeAge} type="primary">
          改变年龄
        </Button>
        <Button onClick={this.add} type="primary">
          加
        </Button>
      </div>
    );
  }
}
const mapStateToProps = (state) => {
  return {
    name: state.name.name,
    number: state.age.number,
  };
};
const mapDispatchToProps = (dispatch) => {
  return {
    setActionsAge: () => {
      return dispatch(actions.setAge(2000));
    },
    setNumber: () => {
      return dispatch(actions.setNumber(2000));
    },
  };
};
export default connect(mapStateToProps, mapDispatchToProps)(Name);
